package com.example.zhang;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.annotation.NonNull;

import org.json.JSONException;
import org.json.JSONObject;

public class Getout_en implements Runnable {

    private static String APP_ID ;
    private static String SECURITY_KEY ;
    private static final String TAG = "a";
    private String input;
    private String out1="123";
    private Handler handler;

    public Getout_en(String app_id, String security_key, String input){
        this.APP_ID = app_id;
        this.SECURITY_KEY = security_key;
        this.input = input;
    }
    public String get_result() throws InterruptedException {
        Thread t = new Thread((Runnable) this);//开启后会启动子线程中的run方法.
        t.start();
        t.join();
        return out1;
    }
    public void run() {
        if (input == null) {
            out1="";
        } else {
            TransApi api = new TransApi(APP_ID, SECURITY_KEY);
            String str = api.getTransResult(input, "auto", "en");
            try {

                JSONObject jsonObject = new JSONObject(str);
                String out = jsonObject.getString("trans_result");
                out = out.substring(1, out.length() - 1);
                JSONObject js = new JSONObject(out);
                out1 = js.getString("dst");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

}
